﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Golf.Model;
namespace Golf.BLL
{
	/// <summary>
	/// Golf_Order
	/// </summary>
	public partial class Golf_Order
	{
		private readonly Golf.DAL.Golf_Order dal=new Golf.DAL.Golf_Order();
		public Golf_Order()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Golf.Model.Golf_Order model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Golf.Model.Golf_Order model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Golf.Model.Golf_Order GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Golf.Model.Golf_Order GetModelByCache(int Id)
		{
			
			string CacheKey = "Golf_OrderModel-" + Id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Golf.Model.Golf_Order)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Golf.Model.Golf_Order> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Golf.Model.Golf_Order> DataTableToList(DataTable dt)
		{
			List<Golf.Model.Golf_Order> modelList = new List<Golf.Model.Golf_Order>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Golf.Model.Golf_Order model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Golf.Model.Golf_Order();
					if(dt.Rows[n]["Id"]!=null && dt.Rows[n]["Id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
					}
					if(dt.Rows[n]["OrderNumber"]!=null && dt.Rows[n]["OrderNumber"].ToString()!="")
					{
					model.OrderNumber=dt.Rows[n]["OrderNumber"].ToString();
					}
					if(dt.Rows[n]["OrderSumPrice"]!=null && dt.Rows[n]["OrderSumPrice"].ToString()!="")
					{
						model.OrderSumPrice=decimal.Parse(dt.Rows[n]["OrderSumPrice"].ToString());
					}
					if(dt.Rows[n]["UserId"]!=null && dt.Rows[n]["UserId"].ToString()!="")
					{
						model.UserId=int.Parse(dt.Rows[n]["UserId"].ToString());
					}
					if(dt.Rows[n]["FristName"]!=null && dt.Rows[n]["FristName"].ToString()!="")
					{
					model.FristName=dt.Rows[n]["FristName"].ToString();
					}
					if(dt.Rows[n]["LastName"]!=null && dt.Rows[n]["LastName"].ToString()!="")
					{
					model.LastName=dt.Rows[n]["LastName"].ToString();
					}
					if(dt.Rows[n]["ProductSumPrice"]!=null && dt.Rows[n]["ProductSumPrice"].ToString()!="")
					{
						model.ProductSumPrice=decimal.Parse(dt.Rows[n]["ProductSumPrice"].ToString());
					}
					if(dt.Rows[n]["TransportationPrice"]!=null && dt.Rows[n]["TransportationPrice"].ToString()!="")
					{
						model.TransportationPrice=decimal.Parse(dt.Rows[n]["TransportationPrice"].ToString());
					}
					if(dt.Rows[n]["MailTypeId"]!=null && dt.Rows[n]["MailTypeId"].ToString()!="")
					{
						model.MailTypeId=int.Parse(dt.Rows[n]["MailTypeId"].ToString());
					}
					if(dt.Rows[n]["IsCoupon"]!=null && dt.Rows[n]["IsCoupon"].ToString()!="")
					{
						if((dt.Rows[n]["IsCoupon"].ToString()=="1")||(dt.Rows[n]["IsCoupon"].ToString().ToLower()=="true"))
						{
						model.IsCoupon=true;
						}
						else
						{
							model.IsCoupon=false;
						}
					}
					if(dt.Rows[n]["CouponPrice"]!=null && dt.Rows[n]["CouponPrice"].ToString()!="")
					{
						model.CouponPrice=decimal.Parse(dt.Rows[n]["CouponPrice"].ToString());
					}
					if(dt.Rows[n]["IsAddPrice"]!=null && dt.Rows[n]["IsAddPrice"].ToString()!="")
					{
						model.IsAddPrice=int.Parse(dt.Rows[n]["IsAddPrice"].ToString());
					}
					if(dt.Rows[n]["AddPriceState"]!=null && dt.Rows[n]["AddPriceState"].ToString()!="")
					{
					model.AddPriceState=dt.Rows[n]["AddPriceState"].ToString();
					}
					if(dt.Rows[n]["AddPrice"]!=null && dt.Rows[n]["AddPrice"].ToString()!="")
					{
						model.AddPrice=decimal.Parse(dt.Rows[n]["AddPrice"].ToString());
					}
					if(dt.Rows[n]["ProductNumberList"]!=null && dt.Rows[n]["ProductNumberList"].ToString()!="")
					{
					model.ProductNumberList=dt.Rows[n]["ProductNumberList"].ToString();
					}
					if(dt.Rows[n]["OrderGeneratedTime"]!=null && dt.Rows[n]["OrderGeneratedTime"].ToString()!="")
					{
						model.OrderGeneratedTime=DateTime.Parse(dt.Rows[n]["OrderGeneratedTime"].ToString());
					}
					if(dt.Rows[n]["OrderVerifyTime"]!=null && dt.Rows[n]["OrderVerifyTime"].ToString()!="")
					{
						model.OrderVerifyTime=DateTime.Parse(dt.Rows[n]["OrderVerifyTime"].ToString());
					}
					if(dt.Rows[n]["VerifyNameId"]!=null && dt.Rows[n]["VerifyNameId"].ToString()!="")
					{
						model.VerifyNameId=int.Parse(dt.Rows[n]["VerifyNameId"].ToString());
					}
					if(dt.Rows[n]["AddressId"]!=null && dt.Rows[n]["AddressId"].ToString()!="")
					{
						model.AddressId=int.Parse(dt.Rows[n]["AddressId"].ToString());
					}
					if(dt.Rows[n]["UserMessage"]!=null && dt.Rows[n]["UserMessage"].ToString()!="")
					{
					model.UserMessage=dt.Rows[n]["UserMessage"].ToString();
					}
					if(dt.Rows[n]["UserIp"]!=null && dt.Rows[n]["UserIp"].ToString()!="")
					{
					model.UserIp=dt.Rows[n]["UserIp"].ToString();
					}
					if(dt.Rows[n]["IsPayment"]!=null && dt.Rows[n]["IsPayment"].ToString()!="")
					{
						model.IsPayment=int.Parse(dt.Rows[n]["IsPayment"].ToString());
					}
					if(dt.Rows[n]["PaymentTypeId"]!=null && dt.Rows[n]["PaymentTypeId"].ToString()!="")
					{
						model.PaymentTypeId=int.Parse(dt.Rows[n]["PaymentTypeId"].ToString());
					}
					if(dt.Rows[n]["PaymentBankId"]!=null && dt.Rows[n]["PaymentBankId"].ToString()!="")
					{
						model.PaymentBankId=int.Parse(dt.Rows[n]["PaymentBankId"].ToString());
					}
					if(dt.Rows[n]["PaymentPrice"]!=null && dt.Rows[n]["PaymentPrice"].ToString()!="")
					{
						model.PaymentPrice=decimal.Parse(dt.Rows[n]["PaymentPrice"].ToString());
					}
					if(dt.Rows[n]["PaymentTime"]!=null && dt.Rows[n]["PaymentTime"].ToString()!="")
					{
						model.PaymentTime=DateTime.Parse(dt.Rows[n]["PaymentTime"].ToString());
					}
					if(dt.Rows[n]["PaymentOrderNumber"]!=null && dt.Rows[n]["PaymentOrderNumber"].ToString()!="")
					{
					model.PaymentOrderNumber=dt.Rows[n]["PaymentOrderNumber"].ToString();
					}
					if(dt.Rows[n]["RefundTypeId"]!=null && dt.Rows[n]["RefundTypeId"].ToString()!="")
					{
						model.RefundTypeId=int.Parse(dt.Rows[n]["RefundTypeId"].ToString());
					}
					if(dt.Rows[n]["LogisticsStateId"]!=null && dt.Rows[n]["LogisticsStateId"].ToString()!="")
					{
						model.LogisticsStateId=int.Parse(dt.Rows[n]["LogisticsStateId"].ToString());
					}
					if(dt.Rows[n]["Logisticsnumber"]!=null && dt.Rows[n]["Logisticsnumber"].ToString()!="")
					{
					model.Logisticsnumber=dt.Rows[n]["Logisticsnumber"].ToString();
					}
					if(dt.Rows[n]["PenskeLogistics"]!=null && dt.Rows[n]["PenskeLogistics"].ToString()!="")
					{
					model.PenskeLogistics=dt.Rows[n]["PenskeLogistics"].ToString();
					}
					if(dt.Rows[n]["LogisticsRemarks"]!=null && dt.Rows[n]["LogisticsRemarks"].ToString()!="")
					{
					model.LogisticsRemarks=dt.Rows[n]["LogisticsRemarks"].ToString();
					}
					if(dt.Rows[n]["OrderStateCodeId"]!=null && dt.Rows[n]["OrderStateCodeId"].ToString()!="")
					{
						model.OrderStateCodeId=int.Parse(dt.Rows[n]["OrderStateCodeId"].ToString());
					}
					if(dt.Rows[n]["ProductOrderNumber"]!=null && dt.Rows[n]["ProductOrderNumber"].ToString()!="")
					{
						model.ProductOrderNumber=int.Parse(dt.Rows[n]["ProductOrderNumber"].ToString());
					}
					if(dt.Rows[n]["IsDeliver"]!=null && dt.Rows[n]["IsDeliver"].ToString()!="")
					{
						if((dt.Rows[n]["IsDeliver"].ToString()=="1")||(dt.Rows[n]["IsDeliver"].ToString().ToLower()=="true"))
						{
						model.IsDeliver=true;
						}
						else
						{
							model.IsDeliver=false;
						}
					}
					if(dt.Rows[n]["DeliverTime"]!=null && dt.Rows[n]["DeliverTime"].ToString()!="")
					{
						model.DeliverTime=DateTime.Parse(dt.Rows[n]["DeliverTime"].ToString());
					}
					if(dt.Rows[n]["DeliverUnitId"]!=null && dt.Rows[n]["DeliverUnitId"].ToString()!="")
					{
						model.DeliverUnitId=int.Parse(dt.Rows[n]["DeliverUnitId"].ToString());
					}
					if(dt.Rows[n]["IsPrintDeliver"]!=null && dt.Rows[n]["IsPrintDeliver"].ToString()!="")
					{
						if((dt.Rows[n]["IsPrintDeliver"].ToString()=="1")||(dt.Rows[n]["IsPrintDeliver"].ToString().ToLower()=="true"))
						{
						model.IsPrintDeliver=true;
						}
						else
						{
							model.IsPrintDeliver=false;
						}
					}
					if(dt.Rows[n]["AllocateUnitId"]!=null && dt.Rows[n]["AllocateUnitId"].ToString()!="")
					{
						model.AllocateUnitId=int.Parse(dt.Rows[n]["AllocateUnitId"].ToString());
					}
					if(dt.Rows[n]["AllocateTime"]!=null && dt.Rows[n]["AllocateTime"].ToString()!="")
					{
						model.AllocateTime=DateTime.Parse(dt.Rows[n]["AllocateTime"].ToString());
					}
					if(dt.Rows[n]["AdminMessageId"]!=null && dt.Rows[n]["AdminMessageId"].ToString()!="")
					{
						model.AdminMessageId=int.Parse(dt.Rows[n]["AdminMessageId"].ToString());
					}
					if(dt.Rows[n]["IsShow"]!=null && dt.Rows[n]["IsShow"].ToString()!="")
					{
						if((dt.Rows[n]["IsShow"].ToString()=="1")||(dt.Rows[n]["IsShow"].ToString().ToLower()=="true"))
						{
						model.IsShow=true;
						}
						else
						{
							model.IsShow=false;
						}
					}
					if(dt.Rows[n]["Pro_AttrList"]!=null && dt.Rows[n]["Pro_AttrList"].ToString()!="")
					{
					model.Pro_AttrList=dt.Rows[n]["Pro_AttrList"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

		#endregion  Method
	}
}

